//
//  HappyPlayCollectionCell.m
//  HappyBaby
//
//  Created by lanou on 15/11/24.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "HappyPlayCollectionCell.h"
#import "Define.h"
#import "UIImageView+WebCache.h"

@interface HappyPlayCollectionCell ()

@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *category;
@property (nonatomic, strong) UILabel *postTitle;

@end

@implementation HappyPlayCollectionCell
{
    CGFloat scale ;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        scale = kScreenHeight / 667;
        CGFloat imageWidth = frame.size.width; // 图片的宽高相等
        
        self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imageWidth, imageWidth)];
        self.iconImageView.layer.cornerRadius = 5;
        self.iconImageView.layer.masksToBounds = YES;
        self.iconImageView.backgroundColor = [UIColor cyanColor];
        [self.contentView addSubview:self.iconImageView];
        
        self.postTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, imageWidth, imageWidth, 60 * scale)];
        self.postTitle.text = @"\t  空间发的流口水；啊 了空间的撒 佛啊";
        self.postTitle.numberOfLines = 2;
        self.postTitle.font = [UIFont boldSystemFontOfSize:kScreenWidth / 26];
        self.postTitle.textColor = [UIColor grayColor];
        [self.contentView addSubview: self.postTitle];
        
        // 创建分类label
        self.category = [[UILabel alloc] initWithFrame:CGRectMake(0, 12 , 30, 18)];
        self.category.textColor = [UIColor whiteColor];
        self.category.textAlignment = NSTextAlignmentCenter;
        self.category.layer.cornerRadius = 3;
        self.category.layer.masksToBounds = YES;
        self.category.font = [UIFont boldSystemFontOfSize:kScreenWidth / 27];
        [self.postTitle addSubview:self.category];
        
                
        
    }
    return self;
}

- (void)setHappyModel:(HappyModel *)happyModel
{
    _happyModel = happyModel;
    NSURL *url = nil;
    
    if (happyModel.post_cover_image) {
       url = [NSURL URLWithString:happyModel.post_cover_image];
    }
    [self.iconImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoldImage1"]];
    self.category.text = [happyModel.post_category substringToIndex:2];
    self.postTitle.text = [NSString stringWithFormat:@"\t  %@",happyModel.post_title];
    if ([self.category.text isEqualToString:@"绘本"]) {
        self.category.backgroundColor = [UIColor colorWithRed:71/225.0 green:168/225.0 blue:254/225.0 alpha:1];
        self.category.text = @"童书";
    }else if ([self.category.text isEqualToString:@"游戏"]){
        self.category.backgroundColor = [UIColor colorWithRed:236/225.0 green:116/225.0 blue:176/225.0 alpha:1];
    }else if ([self.category.text isEqualToString:@"玩具"]){
        self.category.backgroundColor = [UIColor colorWithRed:55/225.0 green:169/225.0 blue:131/225.0 alpha:1];
    }
    
}

@end
